<?php
	require_once("utils.php");
	require_once("obj/session.php");
	require_once("obj/user.php");
	require_once("obj/task.php");
	require_once("obj/tasktime.php");
		
	$tasktime = TaskTime::getFromUrl();
	
	$task = Task::getFromUrl();
	
	if(isset($_POST["btnSubmit"])){
		if($_POST["btnSubmit"] == "Save") {
			$tasktime->TaskId = $task->TaskId;
			$tasktime->UserId = $user->UserId;
			$tasktime->Hours = $_POST["txtHours"];
			$tasktime->Description = $_POST["txtDescription"];
			$tasktime->save();			
		}
		else if($_POST["btnSubmit"] == "Delete") { 
			$tasktime->delete();
		}
		
		$err = error_get_last();
		if (empty($err)) {
			$u = Utils::makeTaskTimeUrl($tasktime->TaskId);
			header("Location:$u");
		}
	}
?>

<form method="post" action="<?php echo Utils::makeTaskTimeDetailUrl($task->TaskId,$tasktime->TaskTimeId);?>">
	<table cellpadding="5" cellspacing="0" border="0">
		<tr>
			<td>Hours:</td>
			<td><input type="text" name="txtHours" id="txtHours" value="<?php echo $tasktime->Hours; ?>" /></td>
		</tr>
		<tr>
			<td valign="top">Description:</td>
			<td>
				<textarea name="txtDescription" id="txtDescription"><?php echo $tasktime->Description; ?></textarea>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<input name="btnSubmit" type="submit" value="Save" />
				<input name="btnSubmit" type="submit" value="Delete" />
				<input type="button" value="Cancel" onclick="javascript:history.back();" />
			</td>
		</tr>
	</table>
</form>